/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package myetl;

import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.ini4j.Wini;

/**
 *
 * @author apuangr1
 */
public class AppManager {
    private DestData destData;
    private SourceData sourceData;
    private Wini ini;
    private Connection sourceConn;
    private Connection destConn;
    private String sourceDriver;
    private String sourceHost;
    private String sourceDB;
    private String sourceLogin;
    private String SourcePassword;
    private String sourceSyntax;
    private String sourceTable;
    private String sourceColumns;
    private String sourceCriteria;
    private String destDriver;
    private String destHost;
    private String destDB;
    private String destLogin;
    private String destPassword;
    private String destSyntax;
    private String destTable;
    private String destColumns;
    private String destCriteria;
    String fileName;
    private String destKeys;

    public void init(String file) {
        try {
            // TODO code application logic here
            ini = new Wini(new File(file));
//            this.sourceDriver = ini.get("database driver", "source");
//            String destination = ini.get("database driver", "destination");
//            System.out.println(source + ":" + destination);
//            String sourceTable = ini.get("destination data", "table");
//            System.out.println("########" + sourceTable);
            initSourceDB();
            initDestinationDB();
//            System.exit(0);

        } catch (IOException ex) {
            Logger.getLogger(AppManager.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void initSourceDB() {
        try {
           
//            this.sourceDriver = ini.get("database driver", "source");
//            this.sourceSyntax = ini.get("database driver", "source connection syntax");
//            this.sourceHost = ini.get("source database", "server");
//            this.sourceDB = ini.get("source database", "database");
//            String conn = this.sourceSyntax.replace("[server]", this.sourceHost);
            
            this.sourceTable = ini.get("source data", "table");
            this.sourceColumns = ini.get("source data", "columns");
            this.sourceCriteria = ini.get("source data", "criteria");
            
//            conn = conn.replace("[database]", this.sourceDB);
//            Class.forName(this.sourceDriver);
//            sourceConn = DriverManager.getConnection(conn);


//            System.out.println("************" + SourceData);

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    private void initDestinationDB() {
        try {
//            this.destDriver = ini.get("database driver", "destination");
//            this.destSyntax = ini.get("database driver", "destination connection syntax");
//            this.destHost = ini.get("destination database", "server");
//            this.destDB = ini.get("destination database", "database");
//            String conn = this.destSyntax.replace("[server]", this.destHost);
            this.destTable = ini.get("destination data", "table");
            this.destColumns = ini.get("destination data", "columns");
            this.destCriteria = ini.get("destination data", "criteria");
//            this.destLogin = ini.get("destination database", "login");
//            this.destPassword = ini.get("destination database", "password");
            this.destKeys             = ini.get("destination data", "keys");
//            Class.forName(this.destDriver);
//            conn = conn.replace("[database]", this.destDB);
//            destConn = DriverManager.getConnection(conn, this.destLogin, this.destPassword);

   

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    /**
     * @return the sourceConn
     */
    public Connection getSourceConn() {
        return sourceConn;
    }

    /**
     * @param sourceConn the sourceConn to set
     */
    public void setSourceConn(Connection sourceConn) {
        this.sourceConn = sourceConn;
    }

    /**
     * @return the destConn
     */
    public Connection getDestConn() {
        return destConn;
    }

    /**
     * @param destConn the destConn to set
     */
    public void setDestConn(Connection destConn) {
        this.destConn = destConn;
    }

    /**
     * @return the ini
     */
    public Wini getIni() {
        return ini;
    }

    /**
     * @param ini the ini to set
     */
    public void setIni(Wini ini) {
        this.ini = ini;
    }

    /**
     * @return the sourceDriver
     */
    public String getSourceDriver() {
        return sourceDriver;
    }

    /**
     * @param sourceDriver the sourceDriver to set
     */
    public void setSourceDriver(String sourceDriver) {
        this.sourceDriver = sourceDriver;
    }

    /**
     * @return the sourceHost
     */
    public String getSourceHost() {
        return sourceHost;
    }

    /**
     * @param sourceHost the sourceHost to set
     */
    public void setSourceHost(String sourceHost) {
        this.sourceHost = sourceHost;
    }

    /**
     * @return the sourceDB
     */
    public String getSourceDB() {
        return sourceDB;
    }

    /**
     * @param sourceDB the sourceDB to set
     */
    public void setSourceDB(String sourceDB) {
        this.sourceDB = sourceDB;
    }

    /**
     * @return the sourceLogin
     */
    public String getSourceLogin() {
        return sourceLogin;
    }

    /**
     * @param sourceLogin the sourceLogin to set
     */
    public void setSourceLogin(String sourceLogin) {
        this.sourceLogin = sourceLogin;
    }

    /**
     * @return the SourcePassword
     */
    public String getSourcePassword() {
        return SourcePassword;
    }

    /**
     * @param SourcePassword the SourcePassword to set
     */
    public void setSourcePassword(String SourcePassword) {
        this.SourcePassword = SourcePassword;
    }

    /**
     * @return the sourceSyntax
     */
    public String getSourceSyntax() {
        return sourceSyntax;
    }

    /**
     * @param sourceSyntax the sourceSyntax to set
     */
    public void setSourceSyntax(String sourceSyntax) {
        this.sourceSyntax = sourceSyntax;
    }

    /**
     * @return the sourceTable
     */
    public String getSourceTable() {
        return sourceTable;
    }

    /**
     * @param sourceTable the sourceTable to set
     */
    public void setSourceTable(String sourceTable) {
        this.sourceTable = sourceTable;
    }

    /**
     * @return the sourceColumns
     */
    public String getSourceColumns() {
        return sourceColumns;
    }

    /**
     * @param sourceColumns the sourceColumns to set
     */
    public void setSourceColumns(String sourceColumns) {
        this.sourceColumns = sourceColumns;
    }

    /**
     * @return the sourceCriteria
     */
    public String getSourceCriteria() {
        return sourceCriteria;
    }

    /**
     * @param sourceCriteria the sourceCriteria to set
     */
    public void setSourceCriteria(String sourceCriteria) {
        this.sourceCriteria = sourceCriteria;
    }

    /**
     * @return the destDriver
     */
    public String getDestDriver() {
        return destDriver;
    }

    /**
     * @param destDriver the destDriver to set
     */
    public void setDestDriver(String destDriver) {
        this.destDriver = destDriver;
    }

    /**
     * @return the destHost
     */
    public String getDestHost() {
        return destHost;
    }

    /**
     * @param destHost the destHost to set
     */
    public void setDestHost(String destHost) {
        this.destHost = destHost;
    }

    /**
     * @return the destDB
     */
    public String getDestDB() {
        return destDB;
    }

    /**
     * @param destDB the destDB to set
     */
    public void setDestDB(String destDB) {
        this.destDB = destDB;
    }

    /**
     * @return the destLogin
     */
    public String getDestLogin() {
        return destLogin;
    }

    /**
     * @param destLogin the destLogin to set
     */
    public void setDestLogin(String destLogin) {
        this.destLogin = destLogin;
    }

    /**
     * @return the destPassword
     */
    public String getDestPassword() {
        return destPassword;
    }

    /**
     * @param destPassword the destPassword to set
     */
    public void setDestPassword(String destPassword) {
        this.destPassword = destPassword;
    }

    /**
     * @return the destSyntax
     */
    public String getDestSyntax() {
        return destSyntax;
    }

    /**
     * @param destSyntax the destSyntax to set
     */
    public void setDestSyntax(String destSyntax) {
        this.destSyntax = destSyntax;
    }

    /**
     * @return the destTable
     */
    public String getDestTable() {
        return destTable;
    }

    /**
     * @param destTable the destTable to set
     */
    public void setDestTable(String destTable) {
        this.destTable = destTable;
    }

    /**
     * @return the destColumns
     */
    public String getDestColumns() {
        return destColumns;
    }

    /**
     * @param destColumns the destColumns to set
     */
    public void setDestColumns(String destColumns) {
        this.destColumns = destColumns;
    }

    /**
     * @return the destCriteria
     */
    public String getDestCriteria() {
        return destCriteria;
    }

    /**
     * @param destCriteria the destCriteria to set
     */
    public void setDestCriteria(String destCriteria) {
        this.destCriteria = destCriteria;
    }

    /**
     * @return the destData
     */
    public DestData getDestData() {
        return destData;
    }

    /**
     * @param destData the destData to set
     */
    public void setDestData(DestData destData) {
        this.destData = destData;
    }

    /**
     * @return the sourceData
     */
    public SourceData getSourceData() {
        return sourceData;
    }

    /**
     * @param sourceData the sourceData to set
     */
    public void setSourceData(SourceData sourceData) {
        this.sourceData = sourceData;
    }
    public String get(String section,  String key){
        return ini.get(section, key);
    }

    /**
     * @return the destKeys
     */
    public String getDestKeys() {
        return destKeys;
    }

    /**
     * @param destKeys the destKeys to set
     */
    public void setDestKeys(String destKeys) {
        this.destKeys = destKeys;
    }
}

